<script setup>
import CompanyLogo from '@/components/CompanyLogo.vue';
import LearnMoreButton from '@/components/LearnMoreButton.vue';
import ThemeToggle from '@/components/ThemeToggle.vue';
import LanguageToggle from '@/components/LanguageToggle.vue';
import LoginButton from '@/components/LoginButton1.vue';
import { ref, onMounted, onBeforeUnmount } from 'vue';
const isMobile = ref(false)
const showMenu = ref(false)
const checkScreenSize = () => {
  isMobile.value = window.innerWidth < 748;
};

onMounted(() => {
  checkScreenSize();
  window.addEventListener('resize', checkScreenSize);
});

onBeforeUnmount(() => {
  window.removeEventListener('resize', checkScreenSize);
});

const stopPropagation = (e) => {
  e.stopPropagation()
}
</script>

<template>
  <div class="header">
    <div class="header-left">
      <CompanyLogo></CompanyLogo>
    </div>
    <div class="header-right" v-if="!isMobile">
      <LearnMoreButton></LearnMoreButton>
      <LanguageToggle></LanguageToggle>
      <ThemeToggle></ThemeToggle>
      <LoginButton></LoginButton>
    </div>
    <div class="mobile-header" v-else>
      <button class="hamburger" @click="showMenu = !showMenu">
        ☰
      </button>
      <div class="mobile-menu" v-if="showMenu" @click="showMenu = false">
        <div class="menu-content">
          <LearnMoreButton></LearnMoreButton>
          <div @click="stopPropagation">
            <LanguageToggle></LanguageToggle>
          </div>
          <div @click="stopPropagation">
            <ThemeToggle></ThemeToggle>
          </div>
          <LoginButton></LoginButton>
        </div>
      </div>
    </div>
  </div>
</template>

<style scope>
.header {
  width: 100%;
  height: 10vh;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2vw;
}

.header-left {
  width: 40%;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60%;
  gap: 4vw;
}

.hamburger {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--txcolor);
  padding: 5px 10px;
}

.mobile-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
}

.menu-content {
  background-color: var(--bgcolor);
  width: 140px;
  height: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
}

@media (max-width: 748px) {
  .header-left {
    width: 60%;
  }

  .mobile-header {
    display: flex;
    justify-content: center;
    width: 40%;
  }
}
</style>